package com.app.serve.common;

import com.app.serve.enums.ErrorCodeEnum;

/**
 *  描述: 通用返回对象
 */
public class JsonResp {

    private Integer code;

    private String msg;

    private Object data;

    private static final int OK_CODE = 10000;

    private static final String OK_MSG = "请求成功!";


    public JsonResp(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public JsonResp(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public JsonResp() {
        this(OK_CODE, OK_MSG);
    }

    public static JsonResp success() {
        return new JsonResp();
    }

    public static JsonResp success(Object data) {
        JsonResp jsonResp = new JsonResp();
        jsonResp.setData(data);
        return jsonResp;
    }

    public static JsonResp success(String msg) {
        JsonResp jsonResp = new JsonResp();
        jsonResp.setMsg(msg);
        return jsonResp;
    }

    public static JsonResp error(ErrorCodeEnum errorCode) {
        return new JsonResp(errorCode.getCode(), errorCode.getMsg());
    }

    public static Object error(Integer code, String msg) {
        return new JsonResp(code, msg);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "JsonResp{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
